package com.roc.web.action.merinfo;

import java.util.ArrayList;
import java.util.List;

import com.roc.page.BaseSearchCondition;
import com.roc.page.WhereHQLFieldBean;
import com.roc.util.Constance;
import com.roc.util.constant.Role;

public class MerchantBelongSearchCondition extends BaseSearchCondition{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private String merNo;
	private String agentId;
	private String orgCode;
	private String roleType;
	
	@Override
	protected List<WhereHQLFieldBean> getWhereHQLFieldBeanList() {
		List<WhereHQLFieldBean> filedBeanList = new ArrayList<WhereHQLFieldBean>();
		//商户号
		if (Constance.isNotEmpty(merNo)) {
			filedBeanList.add(new WhereHQLFieldBean("t.merno", merNo.trim(), "=", false));
		}
				
		if(Constance.isNotEmpty(orgCode)){
			filedBeanList.add(new WhereHQLFieldBean("t.INS_NO", orgCode.trim(), "=", false));
		}
		
		return filedBeanList;
	}

	@Override
	protected String getRowCountHQL() {
		
		String sql = "";
		
		if(Role.AGENT.getCode().equals(roleType) || Role.O_MANAGER.getCode().equals(roleType)){
			sql = " select count(1) "
					+" from TBL_MER_AGENT_RELATION t, "
					+" (SELECT a.id FROM t_operators a  where a.ROLE_TYPE in ('02', '03') "
					+" START WITH a.ID = "+agentId+"  CONNECT BY a.supri_id = PRIOR a.id) b "
					+" where t.AGENTID = b.id ";
		}else{
			sql=" select count(1) "
				+" from TBL_MER_AGENT_RELATION t where 1=1 ";
		}
		
		return sql;
	}

	@Override
	protected String getSearchHQL() {
		
		String sql = "";
		
		if(Role.AGENT.getCode().equals(roleType) || Role.O_MANAGER.getCode().equals(roleType)){
			sql = " select t.AGENTID, t.MERNO, t.MERNAME, t.AGENTNAME, t.INS_NO, t.AGENTTEL "
					+" from TBL_MER_AGENT_RELATION t, "
					+" (SELECT a.id FROM t_operators a  where a.ROLE_TYPE in ('02', '03') "
					+" START WITH a.ID = "+agentId+"  CONNECT BY a.supri_id = PRIOR a.id) b "
					+" where t.AGENTID = b.id ";
		}else{
			sql=" select t.AGENTID, t.MERNO, t.MERNAME, t.AGENTNAME, t.INS_NO, t.AGENTTEL "
				+" from TBL_MER_AGENT_RELATION t where 1=1 ";
		}
		
		return sql;
	}

	@Override
	protected String getOrderPartOfHQL() {
		// TODO Auto-generated method stub
		return "order by t.merno,t.agentId desc ";
	}

	public String getMerNo() {
		return merNo;
	}

	public void setMerNo(String merNo) {
		this.merNo = merNo;
	}

	public String getAgentId() {
		return agentId;
	}

	public void setAgentId(String agentId) {
		this.agentId = agentId;
	}

	public String getOrgCode() {
		return orgCode;
	}

	public void setOrgCode(String orgCode) {
		this.orgCode = orgCode;
	}

	public String getRoleType() {
		return roleType;
	}

	public void setRoleType(String roleType) {
		this.roleType = roleType;
	}

	
}
